using System;
using System.Collections.Generic;
using System.Text;
using emp.Model;
using emp.BLL;
using emp.Utility;
using System.Web;
using System.Collections;
using System.Data;

namespace emp.ProcessFlow
{
   public  class LeadCreateController
    {
       String url_list = "leadlist.aspx";

       public IList getLeadList()
       {
           LeadCreate dal = new LeadCreate();
           return dal.getLeadList();
       }
       public IList getLeadList(String state)
       {
           LeadCreate dal = new LeadCreate();
           return dal.getLeadList(state);
       }
       public bool getLeadInsert(LeadInfo info, IList detailInfo)
       {
           try
           {
               LeadCreate dal = new LeadCreate();
               int i = dal.getLeadInsert(info, detailInfo);
               if (i < 1)
               {
                   return false;
               }

           }
           catch
           {
               string sMethod = "emp.ProcessFlow.leadCreateController.getLeadInsert()";
             //  EventsLog.WriteLog(e, sMethod);
               return false;
           }
           HttpContext.Current.Response.Redirect(url_list, true);
          return true;
       }
       public bool getLeadUpdate(LeadInfo info, IList detailInfo, String  page)
       {
          int i =0;
           try
           {
               LeadCreate dal = new LeadCreate();
               i = dal.getLeadUpdate(info, detailInfo);
               if (i < 1)
               {
                   return false;
               }
           }
           catch
           {
               return false;
           }
           HttpContext.Current.Response.Redirect(url_list + "?cur_page=" + page, true);
           return true;
       }

       public int getBecomeLead(int cac_uid, string inouid, string questid)
       {
           int returnvalue = 0;
           try
           {
               LeadCreate lc = new LeadCreate();
               Campaign_ChannelInfo info = new Campaign_ChannelInfo();
               info = lc.getAssginMode(cac_uid);
               if (info.iCAC_ASSIGN_MODE.Equals("0"))
               {
                   int lcl_uid = info.iCAC_ASSIGN_CONDITION;
                   string condition = lc.getLeadCondition(lcl_uid);
                   Questionnaire qu = new Questionnaire();
                   string condi = condition.Replace("#", questid);

                   returnvalue = qu.executesql("exec p_become_lead_v2 " + inouid + "," + questid + ",'" + condi + "'");
                  
               }

               if (info.iCAC_ASSIGN_MODE.Equals("2"))
               {
                   string condi1="";
                   Questionnaire qu = new Questionnaire();
                   returnvalue = qu.executesql("exec p_become_lead_v2 " + inouid + "," + questid + ",'" + condi1 + "'");
               }
           }
           catch(Exception e)
           {
             
           }
           return returnvalue;
       }
    
    }
}
